<?php
  
  function eform_validation($form) { 
  	//print_r($form); die;
    $stat = new set_static_variable(); 
	
	//Concerned Dept Validation
	//chk_concerned_dept($form['field_eform_dept']);
	
    //Duplicate Title
	//check_title_duplication($form['title'], $form['type']['#value'], $form['field_eform_dept'], 'field_eform_dept', $stat->get_nid());
    $stat->set_nid(0);
	
	// district validation  
	
	 distvalidation($form['field_eform_dist']['und']['#value']);
	 
	/*if(sizeof($form['field_eform_dist']['value']['#value'])>1 && $form['field_eform_dist']['value']['#value'][0]==0){
    
        $field=$form['field_eform_dist']['value']['#value'][0];
        $field_title=$form['field_eform_dist']['#title'];
    form_set_error($field, $field_title . ' field can have either \'ALL\' or \'Other Districts\'');
    }*/
	
    // Check bad character validation
   
   	chkbadchar($form['field_eform_desc']['und'][0]['value']['#value'], $form['field_eform_desc']['und'][0]['value']['#title'], 'field_eform_desc');
    chkbadchar($form['title']['#value'], $form['title']['#title'], 'title'); 
	chkbadchar($form['field_eform_keywords']['und'][0]['value']['#value'],$form['field_eform_keywords']['und'][0]['value']['#title'], 'field_eform_keywords'); 
	chkbadchar($form['field_eform_othercategory']['und'][0]['value']['#value'],$form['field_eform_othercategory']['und'][0]['value']['#title'], 'field_eform_othercategory');
	chkbadchar($form['field_eform_formno']['und'][0]['value']['#value'],$form['field_eform_formno']['und'][0]['value']['#title'], 'field_eform_formno');
	
	// maximum length validation for Title and Description Field
  	maxlength_validation($form['title']['#value'], 255, $form['title']['#title'], 'title');
	
	//echo "ABC".$form['field_eform_desc']['und'][0]['value']['#title'];
	
	// minimum length charcter   
  	minilength_validation($form['title']['#value'], 5, $form['title']['#title'], 'title');
  	minilength_validation($form['field_eform_keywords']['und'][0]['value']['#value'], 5, $form['field_eform_keywords']['und'][0]['value']['#title'],'field_eform_keywords');
	minilength_validation($form['field_eform_desc']['und'][0]['value']['#value'], 5, $form['field_eform_desc']['und'][0]['value']['#title'],'field_eform_desc');
											
	// Date Validation  

    check_scheduler_date_expire($form['scheduler_settings']['unpublish_on']['date']['#value'],'unpublish_on');
													
	check_date_expire($form['field_go_date'][0]['value']['date']['#value'],$form['field_go_date']['#title']);
	
	
  // Form Type validtion
	
 // $form_type = $form['field_eform_type'];
//  
//  if ($form_type['value']['#value'] == 'online') {
//  	
//    $reference_url = $form['field_eform_onurl'][0]['value']['#value'];
//	$reference_url = url_validation($reference_url);
//	
//    if(isURL($reference_url) == 0 && $reference_url != '') {
//      form_set_error('field_eform_onurl', t('Not a valid URL given in %name field', array(
//                                                   '%name' => $form['field_eform_onurl']['#title'])));    
//    }
//    elseif ($reference_url == '') {
//      form_set_error('field_eform_onurl', t(' %name field is required', array(
//                                                   '%name' => $form['field_eform_onurl']['#title'])));
//    }
//  }
//	if ($form_type['value']['#value'] == 'Off-line') {
//    // Validating the file size    
//    $reference_url = $form['field_eform_ofurl'][0]['value']['#value'];
//	
//	//$reference_url = url_validation($reference_url);
//	
//    if(isURL($reference_url) == 0 && $reference_url != '') {
//      form_set_error('field_eform_ofurl', t('Not a valid URL given in %name field', array(
//                                                   '%name' => $form['field_eform_ofurl']['#title'])));    
//    }
//    elseif ($reference_url == '') {
//      form_set_error('field_eform_ofurl', t(' %name field is required', array(
//                                                   '%name' => $form['field_eform_ofurl']['#title'])));
//    }  
//  }
 
  
}
  function eform_presave_validation($node) {
   $reference_url = $node->field_eform_onurl[0]['value'];
   $node->field_eform_onurl[0]['value'] = url_validation($reference_url);
 } // function form_presave_validation()
 